package com.atguigu.tingshu;

import cn.hutool.core.date.DateTime;
import com.atguigu.tingshu.model.user.UserListenProcess;
import com.atguigu.tingshu.user.reporsitory.ListenReporsitory;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;

@SpringBootTest
public class test {

@Autowired
ListenReporsitory mongoRepository;
    @Autowired
    MongoTemplate mongoTemplate;
    @Test
    void test(){
//        LocalDateTime now = LocalDateTime.now();
//        UserListenProcess userListenProcess = new UserListenProcess();
//        userListenProcess.setUserId(1L);
//        userListenProcess.setAlbumId(1610L);
//        userListenProcess.setTrackId(15671L);
//        userListenProcess.setBreakSecond(new BigDecimal(1));
//        userListenProcess.setIsShow(1);
//        userListenProcess.setCreateTime(new DateTime().now());
//        userListenProcess.setUpdateTime(new DateTime().now());
//        System.out.println(mongoRepository.save(userListenProcess));

//        mongoTemplate.remove(new Query(new Criteria()
//                .where("userId").is(1L)
//                .and("albumId").is(1610L)
//                .and("trackId").is(15671L)), UserListenProcess.class);
        List<UserListenProcess> userListenProcesses = mongoTemplate.find(new Query(new Criteria()
                .where("userId").is(1L)
                .and("albumId").is(1610L)
                .and("trackId").is(51951L)), UserListenProcess.class);
        System.out.println(userListenProcesses);
//        LocalDateTime end = LocalDateTime.now();
//        System.out.println(Duration.between(now , end).toMillis());
    }
    @Test
    void testMongo(){
    }
}
